<?php 
	if (strpos(base_url(), '/admin/') === false)
	{
		$hideEditButtons = true;
	}
	else
	{
		$hideEditButtons = false;
	}
?>
<style>
.description_product{
	border: 1px solid #939393;
	background-color: #fff;
	position: relative;
	width: 330px;
}
.writeline{
	border: none;
	padding: 9px 0;
	width: 100%;
	border-top: 1px solid #939393;
	background-color: #fff;
	text-align: center;
	text-transform: uppercase;
	color: #999999;
	font: normal 9px Arial;
	bottom: 0
}
.notes{
	font: bold 12px Arial;
	margin-left: 1px;
	height: 185px;
	overflow-x: hidden;
	overflow-y: auto;
	text-transform: uppercase
}
.brandChatHolder .notes
{
	height: 300px;
}
.userChatHolder .notes
{
	height: 230px;
}
.productNoteChatHolder .notes
{
	height: 300px;
}
.productChatHolder .notes
{
	height: 250px;
}
.productReservedChatHolder .description_product
{
	width: 435px;
}
.productReservedChatHolder .notes
{
	height: 330px;
}
.refundChatHolder .notes
{
	height: 260px;
}
</style>

<div class="formTable">			
	<div class="description_product">
		<div class="notes" id="messageList">
			<table>
			<tbody>
				<?php
					$messageList = $this->note_model->getMessageList($note_model, $note_model_ID);
					
					foreach ($messageList as $k => $v)
					{
				?>
						<tr>
							<td class="note_date">
								<?php echo date('Y-m-d', strtotime($v['note_created'])) ?>
								(<?php echo $v['fullname'] ?>)
							</td>
							<td><?php echo $v['note_text'] ?></td>
							<?php if (!$hideEditButtons) {?>
							<td>
								<a class="chatWidgetDeleteMessage" href="/admin/notes/delete/<?php echo $v['note_ID'] ?>" onclick="return false;">
									<img src="/layout/admin/img/btn_delete_note.png" width="11" height="11" alt="Delete Comment" title="Delete Comment" />
								</a>
							</td>
							<?php } ?>
						</tr>
				<?php		
					}
				?>
			</tbody>
			</table>
		</div>
		<input id="input_chat" type="text" class="writeline" note_model="<?=$note_model?>" note_model_ID="<?=$note_model_ID?>" 
			value="<?=T_('Напишите здесь новый коммент - нажмите Enter')?>" />
	</div>		
</div>	
<script>
$(document).ready(function() {
	// Comment's chat
    //$("#form_create").bind('submit', function() {return false;});
    
    enableChatWidgetDeleteMessage = function()
    {
    	$('a.chatWidgetDeleteMessage').bind('click', function() {
    		var $this = $(this);

			$.ajax({
				url: $this.attr('href'),
				success: function (data, textStatus)
				{
					$this.parent().parent().remove();
				}
			});

			return false;			
    	})
    }
    
    enableChatWidgetDeleteMessage();	
	
	$("#input_chat").keypress(function (e) {
		var $this = $(this);
		
		if (e.which == 13)
		{
			var currentValue = $this.val();
			
			if (currentValue == '')
			{
				return false;			
			}
			
			$this.val('');
			
			$.ajax({
				type: "POST",
				url: "<?=base_url();?>notes/create/",
				data: 
				{
					note_model: $this.attr('note_model'),
					note_model_ID: $this.attr('note_model_ID'),
					note_text: currentValue
				},
				success: function (data, textStatus)
				{
					$(".notes tbody").append(data);
					enableChatWidgetDeleteMessage();
					$("#messageList").animate({ scrollTop: $("#messageList").attr("scrollHeight") }, 3000);
//					alert(data);
				},
				async: false
			});
		
			return false;			
		}
	});

	var writeline_clicked = false;

	$('.writeline').focus(function () {
		if (writeline_clicked == false)
		{
			$(this).val('');
			writeline_clicked = true;
		}
	});

	$('.cancel').click(function () {
		writeline_clicked = false;
	});   
    	
    
});
</script>
